package org.client.view.manage;


import java.net.*;
import java.io.*;

import org.client.tools.ClientTool;
import org.client.tools.Mdd;
import org.pojo.MessageType;
import org.pojo.User;
import org.pojo.Message.Message;
public class IMLoginClientConServer {

	
	public Socket s;
	public static Client2ServerThread ccst;
	//发送第一次请求
	public boolean sendLoginInfoToServer(Object o)
	{
		boolean b=false;
		try {
			System.out.println("LoginConnectServer,please wait...");
			s=new Socket("127.0.0.1",10000);
			ObjectOutputStream oos=new ObjectOutputStream(s.getOutputStream());
			ObjectInputStream ois=new ObjectInputStream(s.getInputStream());
			Message ml= new Message();
			ml.setMesType(MessageType.message_login);//请求登录
			((User)o).setPassword(Mdd.MD5(((User)o).getPassword()));
			ml.setCon(o);
			oos.writeObject(ml);
			ml=(Message)ois.readObject();
			//这里就是验证用户登录的地方
			if(ml.getMesType().equals(MessageType.message_succeed)){
				User u= (User)ml.getCon();
				ClientTool.currentUser = u;
				//就创建一个该IM号和服务器端保持通讯连接得线程
				ccst = new Client2ServerThread(s,oos,ois);
				b = true;
			}else{
				//关闭Scoket
				oos.close();
				ois.close();
				s.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
			// TODO: handle exception
		}
		return b;
	}
	
}
